package com.gdziarmaga.webshop.review.services;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.gdziarmaga.webshop.review.model.Review;
import com.gdziarmaga.webshop.review.model.ReviewDAO;
import com.gdziarmaga.webshop.utils.filtering.BaseFilter;

@Service("reviewManager")
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public class ReviewManagerImpl implements ReviewManager {

	@Autowired
	private ReviewDAO reviewDAO;

	@Override
	public Review getReviewById(Long ReviewId) {
		return reviewDAO.getById(ReviewId);

	}

	@Override
	public Review getReviewByNick(String nick) {
		return reviewDAO.findProductByNick(nick);
	}

	@Override
	public Review getReviewByReview_date(Date review_date) {
		return reviewDAO.findProductByReview_date(review_date);
	}

	@Override
	public void saveReview(Review review) {
		reviewDAO.save(review);
//		reviewDAO.saveOrUpdate(review);
	}

	@Override
	public List<Review> getReviewsByFilterObject(BaseFilter filter) {
		return reviewDAO.getAll(filter);

	}
}
